#include "Wave.h"

sbit Tx = P1^0;
sbit Rx = P1^1;

void Ut_Wave_Init()
{
	unsigned char i;
	for(i = 0;i<8;i++)
	{
		Tx = 1;
		Delay12us();
		Tx = 0;
		Delay12us();
		
	}
}

unsigned char UT_Wave_dat()
{
	unsigned int Time;
	TMOD &= 0x0f;
	TH1 = TL1 = 0;
	Ut_Wave_Init();
	TR1 = 1;
	while(TF0 = 0&& (RX1 == 1));
	TR1 = 0;
	if(TF0 = 0)
	{
		Time = (TH1 <<8) | TL1;
		return Time * 0.017;//0.017表示12mhz主频，经过12分频，一个周期是1us，运算以后340*T*(10的负六次方)/2就是0.017
	}
	else
	{
		TF0 = 0;
		return 0 ；
	}
		

}